import { Column, ManyToOne, JoinColumn } from "typeorm";

import { VARCHAR50_PG, INTEGER_PG, VARCHAR255_PG, User, Contact, Tradable, SMALLINT_PG, BIGINT_PG, ExtIdTuple } from "qqlx-core";

import { TransformerBigInteger, TransformerInteger, TransformerSmallInt } from "@lib/orm.transfor.number";
import { TransformerVarchar50, TransformerVarchar255 } from "@lib/orm.transfor.string";

import { OwnerIdSchema } from "@/alpha/ext.id.base";

export class IdTradableSchema extends OwnerIdSchema implements ExtIdTuple, Tradable {
  @Column({ transformer: new TransformerVarchar255() })
  tradeId: VARCHAR255_PG = "";

  @Column({ transformer: new TransformerBigInteger(), type: "bigint", nullable: false })
  tradeTime: BIGINT_PG = Date.now().toString();

  @Column({ transformer: new TransformerSmallInt() })
  tradeYear: SMALLINT_PG = -1;

  @Column({ transformer: new TransformerSmallInt() })
  tradeMonth: SMALLINT_PG = -1;

  @Column({ transformer: new TransformerVarchar255() })
  tradeScope: VARCHAR255_PG = "";

  @Column({ transformer: new TransformerVarchar50() })
  refCreatorId!: VARCHAR50_PG;

  @ManyToOne("UserSchema")
  @JoinColumn({ name: "refCreatorId", referencedColumnName: "uuid32" })
  justCreator!: User;

  @Column({ transformer: new TransformerInteger() })
  refContactId!: INTEGER_PG;

  @ManyToOne("ContactSchema")
  @JoinColumn({ name: "refContactId", referencedColumnName: "id" })
  justContact!: Contact;
}
